﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Thingpower.SS.EduOnline.Model;
using Thingpower.SS.EduOnline.Provider;
using SiteServer.Plugin;

namespace Thingpower.SS.EduOnline.WebAPI
{
    [RoutePrefix("eduonline/api/statistic")]
    public class StatisticController : ApiController
    {

        #region 获取所有学员的学习情况统计数据
        [HttpGet, Route("getUserStatistic")]
        public IHttpActionResult UserStudyStatistic()
        {
            return Json<List<UserStudyStatisticInfo>>(UserStudyStatisticDAO.GetAllModelsList());
        }
        #endregion

        #region 获取所有课程的学习情况统计数据
        [HttpGet, Route("getCoursewareStatistic")]
        public IHttpActionResult CoursewareStudyStatistic()
        {
            return Json<List<CoursewareStudyStatisticInfo>>(CoursewareStudyStatisticDAO.GetAllModelsList());
        }
        #endregion

        #region 获取所有课程的参与学员及浏览量
        [HttpGet, Route("getUsersOfCourseware")]
        public IHttpActionResult UsersOfCourseware()
        {
            return Json<List<CoursewareStudyUsersInfo>>(CoursewareStudyUsersDAO.GetAllModelsList());
        }
        #endregion

        #region 获取指定课程的参与学员及浏览量
        [HttpGet, Route("getUsersOfCourseware")]
        public IHttpActionResult UsersOfCourseware([FromUri]int coursewareId)
        {
            return Json<List<CoursewareStudyUsersInfo>>(CoursewareStudyUsersDAO.GetModelsList(coursewareId));
        }
        #endregion

        #region 获取指定学员的参与课程及浏览量
        [HttpGet, Route("getCoursewaresOfUser")]
        public IHttpActionResult CoursewaresOfUser([FromUri]int userId)
        {
            return Json<List<UserStudyCoursewaresInfo>>(UserStudyCoursewaresDAO.GetModelsList(userId));
        }
        #endregion

        #region 前端获取指定学员的参与课程量Top5排行榜
        [HttpGet, Route("getStudyCharts")]
        public IHttpActionResult StudyCharts()
        {
            //bool isUserLoggin = EduOnlinePlugin.Instance.Request.IsUserLoggin;
            //int topNum = 5;

            //if (isUserLoggin) {
            //    return Json<List<UserStudyStatisticInfo>>(UserStudyStatisticDAO.GetTopModelsListForFrontEnd(topNum));
            //}
            //else {
            //    return Ok("请先登录");
            //}
            int topNum = 5;
            return Json<List<UserStudyStatisticSEInfo>>(UserStudyStatisticSEDAO.GetTopModelsList(topNum));
        }
        #endregion

        #region 获取热门课程
        [HttpGet, Route("getHotCoursewares")]
        public IHttpActionResult HotCoursewares([FromUri]int topNum)
        {
            return Json<List<CoursewareStudyStatisticInfo>>(CoursewareStudyStatisticDAO.GetTopModelsList(topNum));
        }
        #endregion
    }
}